Add koltin multiplatform client SDK with codegen, gradle plugin and templates#4738
Add koltin multiplatform client SDK with codegen, gradle plugin and templates#4738FromWau wants to merge 194 commits into
Conversation
kotlin: cleanup
|
Hi, I actually created a parallel PR (#5033), because I hadn't seen your work. I like the general work and the usage of a gradle plugin.
Why not just pass CreateRoleArgs, since that also lets people write mappers to cleanly convert like: And it also skips the additional mapping val
|
|
Hi @FromWau, thank you for opening this PR. At the moment we are refraining from expanding language support until we have done a bit more legwork. See Tyler's comment here: #4471 (comment). We will keep this as a reference implementation for once we have done that legwork! |
Description of Changes
Adds a Kotlin Multiplatform client SDK for SpacetimeDB with full code generation support, gradle plugin to auto generate bindings, templates, docs, (ai agent) skills and smoketests.
Note: There is an existing PR for a Kotlin SDK (#4472 by @AndroidPoet). We developed independently. That PR provides a SDK without codegen, using raw byte data. So users have to manually encode/decode BSATN bytes and use string-based reducer names. This PR includes: Rust codegen generating typed table handles, reducers, and procedures, a Gradle plugin that auto-generates bindings on build, two project templates, and smoketests.
Rust cli:
Codegen (Rust):
SDK runtime:
Gradle plugin:
Templates:
Example chat between android and desktop (jvm) using
compose-kttemplate:Jvm


Android
Benchmark:
Added Keynote-1 benchmark client (templates/keynote-2/spacetimedb-kotlin-client/): TPS benchmark matching the Rust client methodology.
Benchmark was run on: i7-12700H, 8GB Ram using 10 connections, 10s, alpha=1.5, confirmed reads
API and ABI breaking changes
CI now requires JDK 21+ installed in the smoketests job. The
spacetimedb-new-runner-2runner needs JDK 21+ available or the Kotlin tasks will fail.No API or ABI breaking changes otherwise.
Expected complexity level and risk
2
The SDK and codegen are self-contained. The only touchpoints with existing code are:
No changes to existing SDK behavior or server-side code.
Testing
Note: sdk and templates are tested against Android and JVM (Linux). I do not have an iOS device so i could not test against native.
cargo test -p spacetimedb-codegen(snapshot tests pass)cargo test -p spacetimedb-smoketests --test integration kotlin(unit tests, build validation, server integration)cargo test -p spacetimedb-smoketests --test integration test_all_templates(basic-kt and compose-kt)sdks/kotlin/./gradlew :spacetimedb-sdk:jvmTestsdks/kotlin/./gradlew :codegen-tests:test(generated bindings compile)cargo fmt+clippyreport no warningsspacetimedb-cli init --template basic-ktcreates a working projectspacetimedb-cli init --template compose-ktcreates a working projectStep-by-step: Testing the compose-kt template locally
Prerequisites: JDK 21+, Rust toolchain, For Android testing: Android emulator or device with adb
1. Clone and build
git clone https://github.com/FromWau/SpacetimeDB.git /tmp/spacetimedb-kotlin cd /tmp/spacetimedb-kotlin git checkout feat/kotlin-sdk cargo build --release -p spacetimedb-cli -p spacetimedb-standalone2. Generate the project from template
/tmp/spacetimedb-kotlin/target/release/spacetimedb-cli init \ --template compose-kt \ --project-path /tmp/compose-kt-test/ \ --non-interactive \ compose-kt-test3. Patch local SDK paths (needed because SDK is not yet published to Maven Central)
In
/tmp/compose-kt-test/settings.gradle.kts, uncomment and set the twoincludeBuildlines:pluginManagement { repositories { /* ... */ } // Need to include the Gradle plugin locally because it's not yet published to Maven Central includeBuild("/tmp/spacetimedb-kotlin/sdks/kotlin/spacetimedb-gradle-plugin") } // Need to include the SDK locally because it's not yet published to Maven Central includeBuild("/tmp/spacetimedb-kotlin/sdks/kotlin")In
/tmp/compose-kt-test/sharedClient/build.gradle.kts, add aspacetimedbblock beforekotlin:4. Start the server (in a separate terminal)
5. Publish the module
6. Run the desktop client
cd /tmp/compose-kt-test ./gradlew :desktopApp:run7. Run the Android client (requires emulator or device with
adb)cd /tmp/compose-kt-test ./gradlew :androidApp:installDebugNext steps
This PR needs the SDK and Gradle plugin published to Maven Central before merging. Right now templates and user projects require manually setting local SDK paths and plugin includes to work. Once published, they just pull dependencies from Maven/Gradle like normal. I'd publish under
com.clockworklabs.spacetimedb-sdkandcom.clockworklabs.spacetimedb-plugin. Would need access to thecom.clockworklabsMaven namespace or a new one. If that works for you, I'll add a Kotlin publish workflow to CI.